package com.esri.core.tasks.geodatabase;

import com.esri.core.internal.tasks.PollingHelper;
import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.internal.tasks.d;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.CallbackListener;
import com.esri.core.map.ServerFile;
import com.esri.core.tasks.geodatabase.GeodatabaseStatusInfo;

/* loaded from: classes.dex */
class PollAndFetchGeodatabaseTask extends d<ServerFile> {
    private static final long serialVersionUID = 1;
    private PollingHelper<GeodatabaseStatusInfo, GeodatabaseStatusInfo.Status> _pollingHelper;
    private GeodatabaseStatusInfo _status;

    public PollAndFetchGeodatabaseTask(GeodatabaseStatusInfo geodatabaseStatusInfo, UserCredentials userCredentials) {
        super(null, geodatabaseStatusInfo.getUpdateUrl(), userCredentials);
        this._pollingHelper = new PollingHelper<>();
        this._status = null;
        this._status = geodatabaseStatusInfo;
    }

    public PollAndFetchGeodatabaseTask(GeodatabaseStatusInfo geodatabaseStatusInfo, UserCredentials userCredentials, TaskListener<ServerFile> taskListener) {
        super(null, geodatabaseStatusInfo.getUpdateUrl(), userCredentials, taskListener);
        this._pollingHelper = new PollingHelper<>();
        this._status = null;
        this._status = geodatabaseStatusInfo;
    }

    public void setStatusCallback(GeodatabaseStatusCallback geodatabaseStatusCallback, CallbackListener<?> callbackListener) {
        this._pollingHelper.a(geodatabaseStatusCallback, callbackListener);
    }

    public GeodatabaseStatusInfo getStatus() {
        return this._status;
    }

    @Override // com.esri.core.internal.tasks.a
    public ServerFile execute() throws Exception {
        UserCredentials credentials = getCredentials();
        if (!GeodatabaseStatusInfo.Status.COMPLETED.equals(this._status.getStatus()) && !GeodatabaseStatusInfo.Status.COMPLETED_WITH_ERRORS.equals(this._status.getStatus())) {
            this._status = this._pollingHelper.a(1000L, getServiceURL(), credentials, GeodatabaseStatusInfo.Status.PENDING, new GeodatabaseStatusPollHelper());
        }
        if (GeodatabaseStatusInfo.Status.COMPLETED.equals(this._status.getStatus())) {
            ServerFile serverFile = new ServerFile(this._status.getResultUrl());
            serverFile.setCredentials(getCredentials());
            return serverFile;
        }
        return null;
    }
}
